<!-- Copyright (c) 2022 渝州大数据实验室
 *
 * Lanius is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *
 *     http://license.coscl.org.cn/MulanPSL2
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 -->
<!-- 
* @desc:调度总览单个卡片组件
* @fileName:Card.vue
* @author:zoujunjie
* @date:2022-4-12
!-->
<template>
  <div
    class="card-container"
    :class="targetUrl ? 'has-target' : ''"
    @click="onCardClick()"
  >
    <div class="figure">{{ figure || "-" }}</div>
    <div class="note">{{ displayNote }}</div>
    <div
      class="tag-container"
      :class="tagColor ? `bg-${tagColor}` : 'bg-default'"
    >
      <el-image class="icon" :src="iconUrl" fit="contain"></el-image>
    </div>
  </div>
</template>
<script setup lang="ts">
import { computed, toRefs } from "vue";
import { useRouter } from "vue-router";

//传入参数
interface Props {
  //显示数字
  figure?: String;
  //文本
  note?: String;
  //图标URL
  iconUrl: String;
  //标签颜色：green | blue | red
  tagColor: String;
  //点击跳转的地址
  targetUrl: String;
}
const props = defineProps<Props>();

const router = useRouter();

const displayNote = computed(() => {
  if (props.note) {
    return props.note;
  }
  return "-";
});

const { targetUrl, tagColor, iconUrl } = toRefs(props);

const onCardClick = (): void => {
  if (props.targetUrl) {
    router.push(props.targetUrl + "");
  }
};
</script>
<style scoped lang="scss">
.card-container {
  width: 256px;
  height: 120px;
  position: relative;
  background-color: white;
  margin-right: 20px;
  margin-bottom: 20px;
  .figure {
    font-weight: 700;
    color: black;
    font-size: 30px;
    line-height: 42px;
    margin-left: 30px;
    padding-top: 28px;
  }
  .note {
    margin-top: 9px;
    margin-left: 30px;
    opacity: 50%;
    line-height: 25px;
    font-weight: 700;
    color: #333333;
    font-size: 18px;
  }

  .tag-container {
    position: absolute;
    top: 0;
    right: 20px;
    width: 40px;
    height: 40px;

    display: flex;
    align-items: center;
    justify-content: center;
    .icon {
      width: 24px;
      height: 24px;
    }
  }

  .bg-default {
    background-color: rgba(180, 180, 180, 1);
  }
}
.card-container:hover {
  box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.15);
}
.has-target:hover {
  cursor: pointer;
}
</style>
